﻿@{
    ViewBag.Title = "新增";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
  <link href="~/Content/jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
  <script src="~/Content/jsoneditor/jsoneditor.min.js"></script>
<script>
    function sub() {
        if ($("#servername").val() == "") {
            alert("请填写名称！")
            return false;
        }
        var nodeip = $("#serverip").val();
        if (nodeip == "") {
            alert("请填写IP！");
            return false;
        }
        else {
            //ip地址
            var exp = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
            var reg = nodeip.match(exp);
            if (reg == null) {
                alert("IP地址不合法！");
                return false;
            }
        }
        if ($("#performancecollectconfigjson").val() == "") {
            alert("请填写性能检测内容配置JSON！");
            return false;
        }
        if ($("#monitorcollectconfigjson").val() == "") {
            alert("请填写监控配置JSON！");
            return false;
        }
    }
</script>
<div class="head">
    <div class="title">
        新增服务器信息
    </div>
</div>
<div>
    @Html.ValidationMessage("Error")
    @using (Html.BeginForm("Add", "Cluster", FormMethod.Post, new { enctype = "multipart/form-data", @onsubmit = "return sub()" }))
    {
    <ul class="mydetail">
        <li>
            <label>服务器名称</label><input class="mylongtext" type="text" id="servername" name="servername" />
        </li>
        <li>
            <label>服务器IP</label><input type="text" name="serverip" />
        </li>
        <li>
            <label>是否开启监控</label>
            <select id="ifmonitor" name="ifmonitor">
                <option value="false">关闭</option>
                <option value="true">开启</option>
            </select>（若开启监控，则对应的服务会加载配置json采集数据，否则只保留运行状态，不开启服务器数据采集）
        </li>
        <li>
            <label>性能检测内容配置JSON</label>
            <textarea id="performancecollectconfigjson" name="performancecollectconfigjson" style="height: 500px; width:700px; display:none"></textarea>
            <div id="divperformancecollectconfigjson" style="height: 500px; width:700px; padding-left:190px;"></div>
        </li>
        <li>
            <label>监控配置JSON</label>
            <textarea id="monitorcollectconfigjson" name="monitorcollectconfigjson" style="height: 500px; width:700px;display:none"></textarea>
            <div id="divmonitorcollectconfigjson" style="height: 500px; width:700px;padding-left:190px;"></div>
        </li>
        <li>
            <input type="submit" class="btn1" onclick="$('#performancecollectconfigjson').val(editor.getText()); $('#monitorcollectconfigjson').val(editor2.getText()); " value="提交" />
        </li>
    </ul>
    }
    <script>
        var container, options, json, editor;

        container = document.getElementById('divperformancecollectconfigjson');

        options = {
            mode: 'code',
            modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
            error: function (err) {
                alert(err.toString());
            }
        };

        json = [{ "CollectName": "cpu(%)", "CategoryName": "Processor", "CounterName": "% Processor Time", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 90, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "剩余内存(M)", "CategoryName": "Memory", "CounterName": "Available MBytes", "InstanceName": "", "CollectType": 0, "MoreThanWarningValue": { "Value": 0, "IsWarning": false }, "LessThanWarningValue": { "Value": 500, "IsWarning": true }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "网络发送(字节)/s", "CategoryName": "Network Interface", "CounterName": "Bytes Sent/sec", "InstanceName": "Qualcomm Atheros AR8172_8176_8178 PCI-E Fast Ethernet Controller [NDIS 6.20]", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "网络下载(字节)/s", "CategoryName": "Network Interface", "CounterName": "Bytes Received/sec", "InstanceName": "Qualcomm Atheros AR8172_8176_8178 PCI-E Fast Ethernet Controller [NDIS 6.20]", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "物理磁盘读(字节)/s", "CategoryName": "PhysicalDisk", "CounterName": "Disk Read Bytes/sec", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "物理磁盘写(字节)/s", "CategoryName": "PhysicalDisk", "CounterName": "Disk Write Bytes/sec", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "IIS请求/s", "CategoryName": "Web Service", "CounterName": "Current Connections", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 100, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }];

        editor = new JSONEditor(container, options, json);

        var container2, options2, json2, editor2;

        container2 = document.getElementById('divmonitorcollectconfigjson');

        options2 = {
            mode: 'code',
            modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
            error: function (err) {
                alert(err.toString());
            }
        };

        json2 = [{ "CollectName": "cpu(%)", "CategoryName": "Processor", "CounterName": "% Processor Time", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 90, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "剩余内存(M)", "CategoryName": "Memory", "CounterName": "Available MBytes", "InstanceName": "", "CollectType": 0, "MoreThanWarningValue": { "Value": 0, "IsWarning": false }, "LessThanWarningValue": { "Value": 500, "IsWarning": true }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "网络发送(字节)/s", "CategoryName": "Network Interface", "CounterName": "Bytes Sent/sec", "InstanceName": "Qualcomm Atheros AR8172_8176_8178 PCI-E Fast Ethernet Controller [NDIS 6.20]", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "网络下载(字节)/s", "CategoryName": "Network Interface", "CounterName": "Bytes Received/sec", "InstanceName": "Qualcomm Atheros AR8172_8176_8178 PCI-E Fast Ethernet Controller [NDIS 6.20]", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "物理磁盘读(字节)/s", "CategoryName": "PhysicalDisk", "CounterName": "Disk Read Bytes/sec", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "物理磁盘写(字节)/s", "CategoryName": "PhysicalDisk", "CounterName": "Disk Write Bytes/sec", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 5000000, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "IIS请求/s", "CategoryName": "Web Service", "CounterName": "Current Connections", "InstanceName": "_Total", "CollectType": 0, "MoreThanWarningValue": { "Value": 100, "IsWarning": true }, "LessThanWarningValue": { "Value": 0, "IsWarning": false }, "EqualWarningValue": { "Value": 0, "IsWarning": false } }, { "CollectName": "磁盘使用信息", "CollectType": 1, "LessThanWarningValue": { "Value": 30, "IsWarning": true } }, { "CollectName": "内存使用信息", "CollectType": 1, "MoreThanWarningValue": { "Value": 90, "IsWarning": true } }];

        editor2 = new JSONEditor(container2, options2, json2);
        
</script>
</div>
